package com.xdb.sqlparser.dialect.mysql.ast.expr;

import com.xdb.sqlparser.ast.SQLExpr;
import com.xdb.sqlparser.ast.AbstractSQLExprImpl;
import com.xdb.sqlparser.ast.SQLOrderingSpecification;
import com.xdb.sqlparser.dialect.mysql.visitor.MySqlASTVisitor;
import com.xdb.sqlparser.visitor.SQLAstVisitor;

public class MySqlSelectGroupByExpr extends AbstractSQLExprImpl implements MySqlExpr {

	protected SQLExpr expr;
	protected SQLOrderingSpecification type;

	@Override
	protected void accept0(SQLAstVisitor visitor) {
		MySqlASTVisitor mysqlVisitor = (MySqlASTVisitor) visitor;
		if (mysqlVisitor.visit(this)) {
			acceptChild(visitor, this.expr);
		}

		mysqlVisitor.endVisit(this);
	}

	public SQLExpr getExpr() {
		return expr;
	}

	public void setExpr(SQLExpr expr) {
		expr.setParent(this);
		this.expr = expr;
	}

	public SQLOrderingSpecification getType() {
		return type;
	}

	public void setType(SQLOrderingSpecification type) {
		this.type = type;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		MySqlSelectGroupByExpr other = (MySqlSelectGroupByExpr) obj;
		if (expr != other.expr) {
			return false;
		}
		if (type == null) {
			if (other.type != null) {
				return false;
			}
		} else if (!type.equals(other.type)) {
			return false;
		}
		return true;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((expr == null) ? 0 : expr.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}

}
